import java.util.Arrays;

import static java.util.Arrays.toString;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: XMQ
 * Date: 2022-05-13
 * Time: 14:30
 */

/**
 * swap交换函数
 */
//class Base{
//    public String name;
//    public int age;
//
//    public void func(){
//        System.out.println("这是一个Base的普通方法!");
//    }
//    Base(){
//        System.out.println("base");
//    }
//}
//class Derived extends Base{
//    public int tele;
//
//    public void test(){
//        System.out.println(name);
//        System.out.println(age);
//        System.out.println(tele);
//        func();
//        System.out.println("这是Derived的普通方法！");
//    }
//}
class MyVal{
    int val;
}
public class Test{

    public static void swap(MyVal val1,MyVal val2){
        int tmp = val1.val;
        val1.val = val2.val;
        val2.val = tmp;
    }
    public static void main(String[] args) {
        MyVal value1 = new MyVal();
        value1.val = 10;
        MyVal value2 = new MyVal();
        value2.val = 20;
        System.out.println(value1.val);
        System.out.println(value2.val);

        swap(value1,value2);

        System.out.println(value1.val);
        System.out.println(value2.val);
    }
    public static void swap(int[] array){
        int tmp = array[0];
        array[0] = array[1];
        array[1] = tmp;
    }
    //构造一个交换函数
    public static void main2(String[] args) {
        int[] array = {10,20};
        System.out.println(Arrays.toString(array));

        swap(array);

        System.out.println(Arrays.toString(array));
    }
    public static void main1(String[] args) {
//        Base c = new Base();
//        Base a = new Derived();
//        Base b = new Test1();
//        Derived  d = new Derived();
//        d.test();
//        new Base();
//        new Test();
    }
}
